/*
 * @Author: 冷澄峰 2362919153@qq.com
 * @Date: 2022-11-28 10:09:39
 * @LastEditors: 冷澄峰 2362919153@qq.com
 * @LastEditTime: 2023-02-08 15:41:50
 * @FilePath: \a-vite-project\src\permissions.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import router from "./router";
import { startProgress, closeProgress } from "./plugin/progress"
import { getLocalData } from "./utils/local"
import { useUserInfoStore } from "@/store/modules/userInfo-store";

let flag = true
router.beforeEach(async (to) => {
    const token = getLocalData("token")
    const userStore = useUserInfoStore()
    if (to.path !== '/login') {
        // startProgress()
        if (!!token) {
            if (flag && userStore.menu) {
                flag = false
                userStore.addRouter()

                return to.path
            }
        } else {
            return '/login'
        }
    }


})

router.afterEach(() => {
    // closeProgress()
})



